﻿package frEngine.animateControler.particleControler
{
    import __AS3__.vec.*;
    import com.gengine.gc.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.loaders.*;
    import frEngine.loaders.particleSub.*;
    import frEngine.loaders.particleSub.particleInstance.*;
    import frEngine.math.*;
    import frEngine.shader.filters.*;
    import frEngine.util.*;

    public class ParticleParams extends Object
    {
        public var callBackId:int;
        public var subCallBackId:int;
        public var parserSuccess:Boolean;
        public var useAutoRotate:Boolean = false;
        public var distanceBirthNum:uint;
        public var indexVect:Vector.<uint>;
        public var surfaceData:Object;
        public var distanceBirth:Boolean;
        public var inertiaValue:Number = 0;
        public var birthDistance:int = 1;
        public var blendType:int;
        public var playMode:int;
        public var materialUrl:Object;
        public var doubleFace:Boolean;
        public var randomValue:int = 0;
        public var useTimeGrowth:Boolean;
        public var useSimpleHarmonicVibration:Boolean = false;
        public var lineForceVecor3d:XYZObject;
        public var frictionVecor3d:XYZObject;
        public var shvDirection:XYZObject;
        public var shvValue:XYZObject;
        public var uvStep:XYZObject;
        public var uvFingerFrames:Array;
        public var uvFingerConst:XYZObject;
        public var uvOffset:XYZObject;
        public var emitUserObject:EmitUserObject;
        public var rotateAxisYSpeed:Number;
        public var rotateAxisFlag:String;
        public var offsetSmoothData:Vector.<uint>;
        public var lixinForceSize:Number;
        public var formation:String;
        public var emitter_rad:Number = 0;
        public var emitter_width:Number = 0;
        public var emitter_height:Number = 0;
        public var emitter_length:Number = 0;
        public var emitCountType:String;
        public var birth_rate:Number = 0;
        public var total_number:uint = 0;
        public var speed:Number = 0;
        public var speed_variation:Number = 0;
        public var useEndPoint:Boolean = false;
        public var destinationX:Number = 0;
        public var destinationY:Number = 0;
        public var destinationZ:Number = 0;
        public var speed_direction_variation:Number = 0;
        public var emitterTime:int = 0;
        public var emitterTimeEffectPeriod:Number;
        public var particleLife:int = 0;
        public var emitterLife:int = 0;
        public var perParticleEmitterTime:Number;
        public var display_until:int = 0;
        public var life_variation:int = 0;
        public var size:Number = 0;
        public var size_variation:Number = 0;
        public var growth_time:Number = 0;
        public var fade_time:Number = 0;
        public var useGrowthAndFade:Boolean;
        public var gf_smooth:Boolean = false;
        public var isFadeToGrowth:Boolean;
        public var seed:Number = 0;
        public var totalTime:int = 0;
        public var particleTyp:uint = 0;
        public var standardparticle:uint = 0;
        public var metaparticle_tension:Number = 0;
        public var metaparticle_tension_variation:Number = 0;
        public var motionMultiplier:Number = 1;
        public var faceCamera:Boolean;
        public var faceMovingDirection:Boolean;
        public var maxDuring:Number = 0;
        public var tailEnabled:Boolean;
        public var tailMaxDistance:int = 0;
        public var useScreenEmitter:Boolean = false;
        public var hasCompleted:Boolean;
        public var sizeSmoothData:Vector.<uint>;
        public var useParticleSize:Boolean = false;
        public var uvRepeat:Boolean = true;
        public var useRotateToVelocity:Boolean = false;
        public var numOfmeshVertex:int = 1;
        public var numOfmeshTriangle:int = 1;
        private var _useColor:Boolean;
        private var _useDoubleColor:Boolean = false;
        private var _useAlpha:Boolean;
        private var _useDoubleAlpha:Boolean = false;
        private var posOffset:Vector.<Number>;
        private var speedVect:Vector.<Number>;
        private var particleTime:Vector.<Number>;
        private var posVect:Vector.<Number>;
        private var _callBack:Function;
        private var _colorBitmapData:BitmapData;
        private var _instancingObject:OneParticleInstance;
        private var _emitterObject:EmitterObject;
        private var _autoRotaionInfo:Object;
        private var _directionInfo:Object;
        private var _faceTransform:Matrix3D;
        public var _useGpu:Boolean;
        private var _useThread:Boolean = false;
        private var _step:int = -1;
        public var centerOffset:XYZObject;
        public var colorBitmapdataBytes:ByteArray;
        private static var hasInit:Boolean = initStatic();
        public static var maxConstRegistNum:uint = 90;
        public static var bitmapHeight:int = 8;
        public static var bitmapWidth:int = 128;
        private static var _matrix:Matrix;
        private static var _shape:Shape;
        private static var templeBitmapdata:BitmapData;
        private static const _matrix3d:Matrix3D = new Matrix3D();

        public function ParticleParams(param1:Boolean = false)
        {
            this.surfaceData = new Object();
            this.centerOffset = new XYZObject();
            this._useThread = param1;
            return;
        }// end function

        public function initObjects(param1:OneParticleInstance, param2:Object, param3:Object, param4:Matrix3D) : void
        {
            this._instancingObject = param1;
            this._autoRotaionInfo = param2;
            this._directionInfo = param3;
            this._faceTransform = param4;
            this.useAutoRotate = this._autoRotaionInfo != null;
            return;
        }// end function

        public function nextStepParser() : void
        {
            if (this._step < 0 || this._step > 8)
            {
                return;
            }
            switch(this._step)
            {
                case 0:
                {
                    this.posOffset = this.createParticlePosOffsetVertex(this.numOfmeshVertex, 0);
                    break;
                }
                case 1:
                {
                    var _loc_1:* = this.createPerSpeed(this.posOffset, this.numOfmeshVertex, 1);
                    this.speedVect = this.createPerSpeed(this.posOffset, this.numOfmeshVertex, 1);
                    break;
                }
                case 2:
                {
                    this.particleTime = this.createPerParticleTime(this.numOfmeshVertex, 2);
                    break;
                }
                case 3:
                {
                    this.createParticleVertex(this.speedVect, this.numOfmeshVertex, 3);
                    break;
                }
                case 4:
                {
                    this.createTail(this.numOfmeshVertex);
                    break;
                }
                case 5:
                {
                    this.createParticleUV(this.numOfmeshVertex, 4);
                    break;
                }
                case 6:
                {
                    if (this._autoRotaionInfo)
                    {
                        this.createAutoRoationAngle(this.numOfmeshVertex, 5);
                    }
                    break;
                }
                case 7:
                {
                    break;
                }
                case 8:
                {
                    this.hasCompleted = true;
                    this._callBack = null;
                    break;
                }
                default:
                {
                    break;
                }
            }
            var _loc_1:String = this;
            var _loc_2:* = this._step + 1;
            _loc_1._step = _loc_2;
            return;
        }// end function

        public function clear() : void
        {
            if (this._instancingObject)
            {
                this._instancingObject.dispose();
                this._instancingObject = null;
            }
            this._faceTransform = null;
            this.faceCamera = false;
            this.faceMovingDirection = false;
            this._autoRotaionInfo = null;
            this._directionInfo = null;
            this.emitUserObject = null;
            this._step = -1;
            this.hasCompleted = false;
            this._callBack = null;
            this.indexVect = null;
            this.offsetSmoothData = null;
            this.sizeSmoothData = null;
            this.posOffset = null;
            this.speedVect = null;
            this.particleTime = null;
            this.posVect = null;
            return;
        }// end function

        public function startBuild(param1:Function) : void
        {
            this._callBack = param1;
            this.initEmmiterParams();
            if (this.distanceBirth)
            {
                this.distanceBirthNum = this._instancingObject is MeshParticle ? (20) : (ParticleParams.maxConstRegistNum);
            }
            else
            {
                this.distanceBirthNum = 1;
            }
            this.checkAndBuildSurface(null);
            return;
        }// end function

        public function setEmitterObject(param1:EmitterObject) : void
        {
            this._emitterObject = param1;
            this.useScreenEmitter = this._emitterObject is SkyEmitter;
            return;
        }// end function

        public function getEmitterObject() : EmitterObject
        {
            return this._emitterObject;
        }// end function

        private function checkAndBuildSurface(event:Event = null) : void
        {
            if (this._instancingObject.hasInitOk > 0 && this._emitterObject.initCompleted)
            {
                this._instancingObject.callBack = null;
                this._emitterObject.callBack = null;
                this.numOfmeshVertex = this._instancingObject.mesh.numVertex;
                this.numOfmeshTriangle = this._instancingObject.mesh.indexVector.length / 3;
                if (this._useThread)
                {
                    this.builderSurfaceImp();
                }
                else
                {
                    this._step = 0;
                }
            }
            else
            {
                this._step = -1;
                this._instancingObject.callBack = this.checkAndBuildSurface;
                this._emitterObject.callBack = this.checkAndBuildSurface;
            }
            return;
        }// end function

        public function getColorBitmapdata() : BitmapData
        {
            return this._colorBitmapData;
        }// end function

        private function builderSurfaceImp() : void
        {
            this.posOffset = this.createParticlePosOffsetVertex(this.numOfmeshVertex, 0);
            var _loc_1:* = this.createPerSpeed(this.posOffset, this.numOfmeshVertex, 1);
            this.speedVect = this.createPerSpeed(this.posOffset, this.numOfmeshVertex, 1);
            this.particleTime = this.createPerParticleTime(this.numOfmeshVertex, 2);
            this.createParticleVertex(this.speedVect, this.numOfmeshVertex, 3);
            this.createTail(this.numOfmeshVertex);
            this.createParticleUV(this.numOfmeshVertex, 4);
            if (this._autoRotaionInfo)
            {
                this.createAutoRoationAngle(this.numOfmeshVertex, 5);
                if (!this.faceCamera)
                {
                    this.createAutoRoationAxis(this.numOfmeshVertex, 6);
                }
            }
            if (this.uvFingerConst)
            {
                this.createUvFingerFrame(this.numOfmeshVertex, 7);
            }
            if (this._colorBitmapData != null && this._colorBitmapData.hasOwnProperty("copyPixelsToByteArray"))
            {
                this.colorBitmapdataBytes = new GByteArray();
                this.colorBitmapdataBytes.endian = Endian.LITTLE_ENDIAN;
                var _loc_1:* = this._colorBitmapData;
                _loc_1.this._colorBitmapData["copyPixelsToByteArray"](this._colorBitmapData.rect, this.colorBitmapdataBytes);
                this._colorBitmapData.dispose();
                this._colorBitmapData = null;
            }
            this.hasCompleted = true;
            if (this._callBack != null)
            {
                this._callBack.apply(null, [this]);
            }
            this._callBack = null;
            return;
        }// end function

        private function createUvFingerFrame(param1:uint, param2:int) : void
        {
            var _loc_11:int = 0;
            var _loc_12:Array = null;
            var _loc_13:int = 0;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:int = 0;
            var _loc_3:* = this.surfaceData["" + FilterName_ID.PARAM3_ID + ":4:true"];
            var _loc_4:* = this.distanceBirthNum * this.total_number * param1 * 4;
            if (_loc_3 == null || _loc_3.length != _loc_4)
            {
                _loc_3 = new Vector.<Number>(_loc_4, true);
                this.surfaceData["" + FilterName_ID.PARAM3_ID + ":4:true"] = _loc_3;
            }
            var _loc_5:int = 0;
            var _loc_6:* = this.uvFingerConst.x;
            var _loc_7:* = this.uvFingerConst.y;
            var _loc_8:* = _loc_6 * _loc_7;
            var _loc_9:int = 0;
            if (this.uvFingerFrames.length < this.total_number)
            {
                _loc_11 = this.total_number - this.uvFingerFrames.length;
                _loc_12 = HelpUtils.getRandomArr(this.randomValue, _loc_11, param2);
                _loc_9 = 0;
                while (_loc_9 < _loc_11)
                {
                    
                    this.uvFingerFrames.push(Math.round(_loc_12[_loc_9] * _loc_8));
                    _loc_9++;
                }
            }
            var _loc_10:int = 0;
            while (_loc_10 < this.distanceBirthNum)
            {
                
                _loc_9 = 0;
                while (_loc_9 < this.total_number)
                {
                    
                    _loc_13 = this.uvFingerFrames[_loc_9];
                    _loc_14 = _loc_13 % _loc_6;
                    _loc_15 = int(_loc_13 / _loc_6) % _loc_7;
                    _loc_16 = 0;
                    while (_loc_16 < param1)
                    {
                        
                        _loc_3[_loc_5 + 2] = _loc_14;
                        _loc_3[_loc_5 + 3] = _loc_15;
                        _loc_5 = _loc_5 + 4;
                        _loc_16++;
                    }
                    _loc_9++;
                }
                _loc_10++;
            }
            return;
        }// end function

        private function createTail(param1:uint) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_2:* = this.surfaceData["" + FilterName_ID.POSITION_ID + ":4:true"];
            if (this.distanceBirth)
            {
                _loc_6 = 0;
                _loc_3 = 0;
                while (_loc_3 < this.distanceBirthNum)
                {
                    
                    _loc_4 = 0;
                    while (_loc_4 < this.total_number)
                    {
                        
                        _loc_5 = 0;
                        while (_loc_5 < param1)
                        {
                            
                            _loc_2[_loc_6 * 4 + 3] = _loc_3;
                            _loc_6++;
                            _loc_5++;
                        }
                        _loc_4++;
                    }
                    _loc_3++;
                }
            }
            else if (this.tailEnabled)
            {
                _loc_6 = 0;
                if (this.emitCountType == EngineConstName.emmitUser && this._useGpu)
                {
                    _loc_4 = 0;
                    while (_loc_4 < this.total_number)
                    {
                        
                        _loc_7 = this.emitUserObject.emitAtFrame[_loc_4];
                        _loc_5 = 0;
                        while (_loc_5 < param1)
                        {
                            
                            _loc_2[_loc_6 * 4 + 3] = _loc_7;
                            _loc_6++;
                            _loc_5++;
                        }
                        _loc_4++;
                    }
                }
            }
            return;
        }// end function

        private function initEmmiterParams() : void
        {
            var _loc_1:* = Math.min(this.particleLife, this.emitterTime);
            if (this.emitCountType == EngineConstName.emmitCount)
            {
            }
            else if (this.emitCountType == EngineConstName.emmitRate)
            {
                this.total_number = int(this.birth_rate * _loc_1);
                this.total_number = this.total_number < 1 ? (1) : (this.total_number);
            }
            else
            {
                this.total_number = this.emitUserObject.emitTotalNum;
            }
            if (this.total_number > maxConstRegistNum)
            {
                this.total_number = maxConstRegistNum;
            }
            if (this.emitterTime < 1000)
            {
                if (this.emitCountType == EngineConstName.emmitUser && this.emitterTime < this.emitUserObject.emitMaxTime)
                {
                    this.emitterTime = this.emitUserObject.emitMaxTime;
                }
                if (this.useTimeGrowth)
                {
                    this.emitterTimeEffectPeriod = this.emitterTime;
                    this.emitterLife = this.particleLife + this.emitterTime;
                }
                else
                {
                    this.emitterTimeEffectPeriod = this.emitterTime;
                    this.emitterLife = Math.max(this.particleLife, this.emitterTime);
                }
            }
            else if (this.emitCountType == EngineConstName.emmitUser)
            {
                var _loc_3:* = Math.max(this.particleLife, this.emitUserObject.emitMaxTime);
                this.emitterLife = Math.max(this.particleLife, this.emitUserObject.emitMaxTime);
                this.emitterTimeEffectPeriod = _loc_3;
            }
            else
            {
                var _loc_3:* = this.particleLife;
                this.emitterLife = this.particleLife;
                this.emitterTimeEffectPeriod = _loc_3;
            }
            var _loc_2:* = Math.max(this.emitterTime, this.emitterLife) / this.emitterLife;
            this.maxDuring = int(_loc_2);
            if (this.emitCountType == EngineConstName.emmitUser)
            {
                this.perParticleEmitterTime = 1;
            }
            else
            {
                this.perParticleEmitterTime = this.emitterTimeEffectPeriod / this.total_number;
            }
            return;
        }// end function

        private function createAutoRoationAngle(param1:uint, param2:uint) : void
        {
            var _loc_5:Number = NaN;
            var _loc_6:Number = NaN;
            var _loc_7:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_16:int = 0;
            var _loc_17:Number = NaN;
            var _loc_18:int = 0;
            var _loc_3:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.PARAM3_ID + ":4:true"] = _loc_3;
            var _loc_4:* = this._autoRotaionInfo.angle * MathConsts.DEGREES_TO_RADIANS / 2;
            if (this._autoRotaionInfo.angleVar >= 0)
            {
                _loc_5 = this._autoRotaionInfo.angleVar * _loc_4;
                _loc_6 = _loc_4 - _loc_5;
                _loc_7 = _loc_5 * 2;
            }
            else
            {
                _loc_5 = (-this._autoRotaionInfo.angleVar) * _loc_4;
                _loc_6 = -_loc_5;
                _loc_7 = _loc_5 * 2;
            }
            var _loc_8:* = this._autoRotaionInfo.offsetAngle * MathConsts.DEGREES_TO_RADIANS / 2;
            if (this._autoRotaionInfo.offsetAngleVar >= 0)
            {
                _loc_9 = this._autoRotaionInfo.offsetAngleVar * _loc_8;
                _loc_10 = _loc_8 - _loc_9;
                _loc_11 = _loc_9 * 2;
            }
            else
            {
                _loc_9 = (-this._autoRotaionInfo.offsetAngleVar) * _loc_8;
                _loc_10 = -_loc_9;
                _loc_11 = _loc_9 * 2;
            }
            var _loc_14:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2);
            var _loc_15:int = 0;
            while (_loc_15 < this.distanceBirthNum)
            {
                
                _loc_16 = 0;
                while (_loc_16 < this.total_number)
                {
                    
                    _loc_17 = _loc_14[_loc_16];
                    _loc_12 = _loc_6 + _loc_7 * _loc_17;
                    _loc_13 = _loc_10 + _loc_11 * _loc_17;
                    _loc_18 = 0;
                    while (_loc_18 < param1)
                    {
                        
                        _loc_3.push(_loc_12, _loc_13, 0, 0);
                        _loc_18++;
                    }
                    _loc_16++;
                }
                _loc_15++;
            }
            return;
        }// end function

        private function createParticleUV(param1:uint, param2:uint) : void
        {
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_3:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.UV_ID + ":2:true"] = _loc_3;
            var _loc_4:* = this._instancingObject.mesh.vertexVector;
            var _loc_5:* = this._instancingObject.mesh.sizePerVertex;
            var _loc_6:* = this._instancingObject.mesh.uvOffset;
            var _loc_7:int = 0;
            while (_loc_7 < this.distanceBirthNum)
            {
                
                _loc_8 = 0;
                while (_loc_8 < this.total_number)
                {
                    
                    _loc_9 = 0;
                    while (_loc_9 < param1)
                    {
                        
                        _loc_10 = _loc_9 * _loc_5 + _loc_6;
                        _loc_3.push(_loc_4[_loc_10], _loc_4[(_loc_10 + 1)]);
                        _loc_9++;
                    }
                    _loc_8++;
                }
                _loc_7++;
            }
            return;
        }// end function

        private function createParticlePosOffsetVertex(param1:uint, param2:uint) : Vector.<Number>
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Vector3D = null;
            var _loc_3:* = new Vector.<Number>;
            this._emitterObject.init(this.total_number, this.randomValue, param2);
            _loc_4 = 0;
            while (_loc_4 < this.total_number)
            {
                
                _loc_11 = this._emitterObject.getTargetRondomXYZ(_loc_4);
                _loc_8 = _loc_11.x;
                _loc_9 = _loc_11.y;
                _loc_10 = _loc_11.z;
                _loc_5 = 0;
                while (_loc_5 < param1)
                {
                    
                    _loc_3.push(_loc_8, _loc_9, _loc_10);
                    _loc_5++;
                }
                _loc_4++;
            }
            var _loc_12:* = new Vector.<Number>;
            _loc_6 = 0;
            while (_loc_6 < this.distanceBirthNum)
            {
                
                _loc_12 = _loc_12.concat(_loc_3);
                _loc_6++;
            }
            this.surfaceData["" + FilterName_ID.PARAM1_ID + ":3:true"] = _loc_12;
            return _loc_12;
        }// end function

        private function createParticleVertex(param1:Vector.<Number>, param2:uint, param3:uint) : void
        {
            var _loc_4:* = this._instancingObject.mesh.indexVector;
            this.indexVect = new Vector.<uint>;
            var _loc_5:* = new Matrix3D();
            this._faceTransform = new Matrix3D();
            if (this.useSpeed && this.faceMovingDirection)
            {
                this.posVect = this.createFaceMovingVetexts(param1, _loc_4, param2, param3);
            }
            else
            {
                this.posVect = this.createVertexts(_loc_4, param2, param3);
            }
            if (this._instancingObject.mesh.useAlpha)
            {
                this.createVertextsAlpha(param2);
            }
            return;
        }// end function

        private function createVertextsAlpha(param1:uint) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_2:* = this._instancingObject.mesh.vertexVector;
            var _loc_7:int = 0;
            var _loc_8:* = this._instancingObject.mesh.sizePerVertex;
            var _loc_9:int = 4;
            var _loc_10:* = this.particleTime;
            var _loc_11:int = 3;
            var _loc_12:int = 3;
            _loc_5 = 0;
            while (_loc_5 < this.distanceBirthNum)
            {
                
                _loc_3 = 0;
                while (_loc_3 < this.total_number)
                {
                    
                    _loc_11 = 3;
                    _loc_4 = 0;
                    while (_loc_4 < param1)
                    {
                        
                        _loc_10[_loc_12] = _loc_2[_loc_11];
                        _loc_11 = _loc_11 + _loc_8;
                        _loc_12 = _loc_12 + _loc_9;
                        _loc_4++;
                    }
                    _loc_3++;
                }
                _loc_5++;
            }
            return;
        }// end function

        private function createVertexts(param1:Vector.<uint>, param2:uint, param3:uint) : Vector.<Number>
        {
            var _loc_5:Vector.<Number> = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_12:Number = NaN;
            var _loc_13:int = 0;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:Number = NaN;
            var _loc_4:* = this._instancingObject.mesh.sizePerVertex;
            var _loc_6:* = this._instancingObject.mesh.vertexVector;
            var _loc_11:int = 0;
            if (_loc_4 == 3)
            {
                _loc_5 = _loc_6;
            }
            else
            {
                _loc_5 = new Vector.<Number>;
                _loc_8 = 0;
                while (_loc_8 < param2)
                {
                    
                    _loc_13 = _loc_8 * _loc_4;
                    _loc_5.push(_loc_6[_loc_13] + this.centerOffset.x, _loc_6[(_loc_13 + 1)] + this.centerOffset.y, _loc_6[_loc_13 + 2] + this.centerOffset.z);
                    _loc_8++;
                }
            }
            var _loc_17:* = this.size_variation * this.size;
            var _loc_18:* = this.size - _loc_17;
            var _loc_19:* = _loc_17 * 2;
            var _loc_20:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.POSITION_ID + ":4:true"] = _loc_20;
            var _loc_21:* = param1.length / 3;
            var _loc_22:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param3);
            var _loc_23:* = new Vector3D();
            var _loc_24:* = new Vector.<Number>;
            this._faceTransform.transformVectors(_loc_5, _loc_24);
            _loc_9 = 0;
            while (_loc_9 < this.distanceBirthNum)
            {
                
                _loc_15 = (_loc_9 + _loc_11) * this.total_number;
                _loc_7 = 0;
                while (_loc_7 < this.total_number)
                {
                    
                    _loc_16 = _loc_22[_loc_7];
                    _loc_12 = _loc_18 + _loc_16 * _loc_19;
                    _loc_8 = 0;
                    while (_loc_8 < param2)
                    {
                        
                        _loc_13 = _loc_8 * 3;
                        _loc_20.push(_loc_24[_loc_13] * _loc_12, _loc_24[(_loc_13 + 1)] * _loc_12, _loc_24[_loc_13 + 2] * _loc_12, _loc_7);
                        _loc_8++;
                    }
                    _loc_14 = (_loc_15 + _loc_7) * param2;
                    _loc_8 = 0;
                    while (_loc_8 < _loc_21)
                    {
                        
                        _loc_13 = _loc_8 * 3;
                        this.indexVect.push(_loc_14 + param1[_loc_13], _loc_14 + param1[(_loc_13 + 1)], _loc_14 + param1[_loc_13 + 2]);
                        _loc_8++;
                    }
                    _loc_7++;
                }
                _loc_9++;
            }
            _loc_11 = _loc_11 + this.distanceBirthNum;
            return _loc_20;
        }// end function

        private function createFaceMovingVetexts(param1:Vector.<Number>, param2:Vector.<uint>, param3:uint, param4:uint) : Vector.<Number>
        {
            var _loc_7:Vector.<Number> = null;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:Number = NaN;
            var _loc_12:int = 0;
            var _loc_13:int = 0;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_17:Number = NaN;
            var _loc_27:int = 0;
            var _loc_5:* = this._instancingObject.mesh.vertexVector;
            var _loc_6:* = this._instancingObject.mesh.sizePerVertex;
            var _loc_16:int = 0;
            if (_loc_6 == 3)
            {
                _loc_7 = _loc_5;
            }
            else
            {
                _loc_7 = new Vector.<Number>;
                _loc_13 = 0;
                while (_loc_13 < param3)
                {
                    
                    _loc_8 = _loc_13 * _loc_6;
                    _loc_7.push(_loc_5[_loc_8] + this.centerOffset.x, _loc_5[(_loc_8 + 1)] + this.centerOffset.y, _loc_5[_loc_8 + 2] + this.centerOffset.z);
                    _loc_13++;
                }
            }
            var _loc_18:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.POSITION_ID + ":4:true"] = _loc_18;
            var _loc_19:* = param2.length / 3;
            var _loc_20:* = this.size_variation * this.size;
            var _loc_21:* = this.size - _loc_20;
            var _loc_22:* = _loc_20 * 2;
            var _loc_23:* = 180 / Math.PI;
            var _loc_24:* = new Vector3D();
            var _loc_25:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param4);
            var _loc_26:* = new Vector.<Number>;
            _loc_14 = 0;
            while (_loc_14 < this.distanceBirthNum)
            {
                
                _loc_10 = (_loc_14 + _loc_16) * this.total_number;
                _loc_12 = 0;
                while (_loc_12 < this.total_number)
                {
                    
                    _loc_11 = _loc_25[_loc_12];
                    _loc_17 = _loc_21 + _loc_11 * _loc_22;
                    _loc_27 = param3 * 3 * _loc_12;
                    _loc_24.x = param1[_loc_27++];
                    _loc_24.y = param1[_loc_27++];
                    _loc_24.z = param1[_loc_27];
                    this.calculateOutVect(_loc_26, _loc_24, _loc_17, _loc_7);
                    _loc_13 = 0;
                    while (_loc_13 < param3)
                    {
                        
                        _loc_8 = _loc_13 * 3;
                        _loc_18.push(_loc_26[_loc_8], _loc_26[(_loc_8 + 1)], _loc_26[_loc_8 + 2], _loc_12);
                        _loc_13++;
                    }
                    _loc_9 = (_loc_10 + _loc_12) * param3;
                    _loc_13 = 0;
                    while (_loc_13 < _loc_19)
                    {
                        
                        _loc_8 = _loc_13 * 3;
                        this.indexVect.push(_loc_9 + param2[_loc_8], _loc_9 + param2[(_loc_8 + 1)], _loc_9 + param2[_loc_8 + 2]);
                        _loc_13++;
                    }
                    _loc_12++;
                }
                _loc_14++;
            }
            _loc_16 = _loc_16 + this.distanceBirthNum;
            return _loc_18;
        }// end function

        private function calculateOutVect(param1:Vector.<Number>, param2:Vector3D, param3:Number, param4:Vector.<Number>) : void
        {
            var _loc_5:Vector3D = null;
            param2.normalize();
            _matrix3d.identity();
            if (param2.x == 0 && Math.abs(param2.y) == 1 && param2.z == 0)
            {
                _loc_5 = Vector3D.Z_AXIS;
            }
            else
            {
                _loc_5 = Vector3D.Y_AXIS;
            }
            var _loc_6:* = _loc_5.crossProduct(param2);
            _loc_6.normalize();
            _loc_5 = param2.crossProduct(_loc_6);
            _loc_6.w = 0;
            _loc_5.w = 0;
            param2.w = 0;
            _matrix3d.copyColumnFrom(0, _loc_6);
            _matrix3d.copyColumnFrom(1, _loc_5);
            _matrix3d.copyColumnFrom(2, param2);
            _matrix3d.append(this._faceTransform);
            _matrix3d.appendScale(param3, param3, param3);
            _matrix3d.transformVectors(param4, param1);
            return;
        }// end function

        private function createPerSpeed(param1:Vector.<Number>, param2:uint, param3:uint) : Vector.<Number>
        {
            var _loc_4:* = new Vector.<Number>;
            var _loc_5:* = new PEmitterDirectionInfo(this._directionInfo);
            _loc_5.init(this.total_number, this.randomValue, param3);
            _loc_5.setDirectionVector(this.distanceBirthNum, this.total_number, this.speed_variation, this.speed, _loc_4, param2, param1);
            this.surfaceData["" + FilterName_ID.PARAM2_ID + ":3:true"] = _loc_4;
            return _loc_4;
        }// end function

        private function createPerParticleTime(param1:uint, param2:uint) : Vector.<Number>
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:int = 0;
            var _loc_12:Number = NaN;
            var _loc_13:Number = NaN;
            var _loc_14:int = 0;
            var _loc_3:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.PARAM0_ID + ":4:true"] = _loc_3;
            var _loc_10:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2);
            var _loc_11:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2 + 10);
            if (this.emitCountType == EngineConstName.emmitUser)
            {
                _loc_5 = 0;
                while (_loc_5 < this.distanceBirthNum)
                {
                    
                    _loc_7 = 0;
                    while (_loc_7 < this.total_number)
                    {
                        
                        _loc_12 = _loc_10[_loc_7];
                        _loc_13 = _loc_11[_loc_7];
                        _loc_9 = this.particleLife + this.life_variation * 2 * (_loc_12 - 0.5);
                        var _loc_15:int = 1;
                        _loc_9 = 1;
                        _loc_14 = this.emitUserObject.emitAtFrame[_loc_7];
                        _loc_8 = 0;
                        while (_loc_8 < param1)
                        {
                            
                            _loc_3.push(_loc_14, _loc_9, _loc_13, 1);
                            _loc_8++;
                        }
                        _loc_7++;
                    }
                    _loc_5++;
                }
            }
            else
            {
                _loc_5 = 0;
                while (_loc_5 < this.distanceBirthNum)
                {
                    
                    _loc_7 = 0;
                    while (_loc_7 < this.total_number)
                    {
                        
                        _loc_12 = _loc_10[_loc_7];
                        _loc_13 = _loc_11[_loc_7];
                        _loc_9 = this.particleLife + this.life_variation * 2 * (_loc_12 - 0.5);
                        var _loc_15:int = 1;
                        _loc_9 = 1;
                        _loc_8 = 0;
                        while (_loc_8 < param1)
                        {
                            
                            _loc_3.push(_loc_7, _loc_9, _loc_13, 1);
                            _loc_8++;
                        }
                        _loc_7++;
                    }
                    _loc_5++;
                }
            }
            return _loc_3;
        }// end function

        private function createAutoRoationAxis(param1:uint, param2:uint) : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_9:int = 0;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_12:Number = NaN;
            var _loc_13:int = 0;
            var _loc_14:Vector3D = null;
            var _loc_15:Vector3D = null;
            var _loc_16:Number = NaN;
            var _loc_3:* = new Vector.<Number>;
            this.surfaceData["" + FilterName_ID.PARAM4_ID + ":3:true"] = _loc_3;
            var _loc_6:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2);
            var _loc_7:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2 + 10);
            var _loc_8:* = HelpUtils.getRandomArr(this.randomValue, this.total_number, param2 + 20);
            if (this._autoRotaionInfo.type == 0)
            {
                _loc_4 = 0;
                while (_loc_4 < this.distanceBirthNum)
                {
                    
                    _loc_9 = 0;
                    while (_loc_9 < this.total_number)
                    {
                        
                        _loc_10 = _loc_6[_loc_9];
                        _loc_11 = _loc_7[_loc_9];
                        _loc_12 = _loc_8[_loc_9];
                        _loc_13 = 0;
                        while (_loc_13 < param1)
                        {
                            
                            _loc_3.push(_loc_10, _loc_11, _loc_12);
                            _loc_13++;
                        }
                        _loc_9++;
                    }
                    _loc_4++;
                }
            }
            else
            {
                _loc_14 = new Vector3D();
                _loc_15 = this._autoRotaionInfo.axis;
                _loc_16 = this._autoRotaionInfo.axisVar;
                _loc_15.normalize();
                _loc_4 = 0;
                while (_loc_4 < this.distanceBirthNum)
                {
                    
                    _loc_9 = 0;
                    while (_loc_9 < this.total_number)
                    {
                        
                        _loc_14.x = 0.5 - _loc_6[_loc_9];
                        _loc_14.y = 0.5 - _loc_7[_loc_9];
                        _loc_14.z = 0.5 - _loc_8[_loc_9];
                        _loc_14.normalize();
                        _loc_14.scaleBy(_loc_16);
                        _loc_14 = _loc_14.add(_loc_15);
                        _loc_14.normalize();
                        _loc_10 = _loc_14.x;
                        _loc_11 = _loc_14.y;
                        _loc_12 = _loc_14.z;
                        _loc_13 = 0;
                        while (_loc_13 < param1)
                        {
                            
                            _loc_3.push(_loc_10, _loc_11, _loc_12);
                            _loc_13++;
                        }
                        _loc_9++;
                    }
                    _loc_4++;
                }
            }
            return;
        }// end function

        private function createIndividualPos(param1:uint, param2:uint) : void
        {
            var _loc_5:int = 0;
            var _loc_3:* = new Vector.<Number>;
            var _loc_4:int = 0;
            while (_loc_4 < this.total_number)
            {
                
                _loc_5 = 0;
                while (_loc_5 < param1)
                {
                    
                    _loc_3.push(0, 0, 0, 0);
                    _loc_5++;
                }
                _loc_4++;
            }
            this.surfaceData["" + FilterName_ID.PARAM5_ID + ":4:true"] = _loc_3;
            return;
        }// end function

        public function get hasForce() : Boolean
        {
            return this.useLineForce || this.useLiXinForce;
        }// end function

        public function get useFriction() : Boolean
        {
            return this.frictionVecor3d != null;
        }// end function

        public function get useSpeed() : Boolean
        {
            return this.speed > 0 && !this.useEndPoint;
        }// end function

        public function get useLineForce() : Boolean
        {
            return this.lineForceVecor3d != null;
        }// end function

        public function get useLiXinForce() : Boolean
        {
            return this.lixinForceSize != 0;
        }// end function

        public function get useRotateAxisY() : Boolean
        {
            return this.rotateAxisYSpeed != 0;
        }// end function

        public function get useAlpha() : Boolean
        {
            return this._useAlpha;
        }// end function

        public function get useDoubleAlpha() : Boolean
        {
            return this._useDoubleAlpha;
        }// end function

        public function get useColor() : Boolean
        {
            return this._useColor;
        }// end function

        public function get useDoubleColor() : Boolean
        {
            return this._useDoubleColor;
        }// end function

        public function setDoubleColor(param1:Array, param2:Array, param3:Array) : void
        {
            if (param1 && param2 && param3)
            {
                this._useDoubleColor = true;
                if (!this._colorBitmapData)
                {
                    this._colorBitmapData = new BitmapData(bitmapWidth, bitmapHeight, false, 16777215);
                }
                _shape.graphics.beginGradientFill(GradientType.LINEAR, param1, param2, param3, _matrix, "pad", InterpolationMethod.RGB);
                _shape.graphics.drawRect(0, 1, bitmapWidth, 1);
                this._colorBitmapData.draw(_shape);
            }
            else
            {
                this._useDoubleColor = false;
            }
            return;
        }// end function

        public function setDoubleAlpha(param1:Array, param2:Array, param3:Array) : void
        {
            if (param1 && param2 && param3)
            {
                this._useDoubleAlpha = true;
                if (!this._colorBitmapData)
                {
                    this._colorBitmapData = new BitmapData(bitmapWidth, bitmapHeight, false, 16777215);
                }
                _shape.graphics.clear();
                _shape.graphics.beginGradientFill(GradientType.LINEAR, param1, param2, param3, _matrix, "pad", InterpolationMethod.RGB);
                _shape.graphics.drawRect(0, 3, bitmapWidth, 1);
                this._colorBitmapData.draw(_shape);
            }
            else
            {
                this._useDoubleAlpha = false;
            }
            return;
        }// end function

        public function setUvOffsetSmooth(param1:Array) : void
        {
            if (param1 && param1.length > 1)
            {
                if (!this._colorBitmapData)
                {
                    this._colorBitmapData = new BitmapData(bitmapWidth, bitmapHeight, false, 16777215);
                }
                this.offsetSmoothData = this.calculateFrameValue(param1);
                this._colorBitmapData.setVector(new Rectangle(0, 4, bitmapWidth, 1), this.offsetSmoothData);
            }
            else
            {
                this.offsetSmoothData = null;
            }
            return;
        }// end function

        public function setSizeSmooth(param1:Array) : void
        {
            if (param1 && param1.length > 1)
            {
                this.sizeSmoothData = this.calculateFrameValue(param1);
            }
            else
            {
                this.sizeSmoothData = null;
            }
            return;
        }// end function

        private function calculateFrameValue(param1:Array) : Vector.<uint>
        {
            var _loc_10:int = 0;
            var _loc_11:uint = 0;
            var _loc_12:Number = NaN;
            var _loc_14:Object = null;
            var _loc_15:Boolean = false;
            var _loc_16:Number = NaN;
            var _loc_17:int = 0;
            var _loc_18:Boolean = false;
            var _loc_19:uint = 0;
            var _loc_20:Number = NaN;
            var _loc_21:Number = NaN;
            var _loc_22:Number = NaN;
            var _loc_23:Number = NaN;
            var _loc_2:* = param1.length;
            var _loc_3:* = param1[0];
            var _loc_4:* = new Vector3D();
            var _loc_5:* = new Vector3D();
            var _loc_6:* = _loc_3.isLineTween == null ? (true) : (_loc_3.isLineTween);
            var _loc_7:* = Number(_loc_3.attributes);
            var _loc_8:* = _loc_3.index / 100 * bitmapWidth;
            var _loc_9:* = new Vector.<uint>;
            var _loc_13:int = 1;
            while (_loc_13 < _loc_2)
            {
                
                _loc_14 = param1[_loc_13];
                _loc_15 = _loc_14.isLineTween == null ? (true) : (_loc_14.isLineTween);
                _loc_16 = Number(_loc_14.attributes);
                _loc_17 = _loc_14.index / 100 * bitmapWidth;
                _loc_18 = _loc_6 || _loc_15;
                if (_loc_18)
                {
                    _loc_19 = _loc_17 - _loc_8;
                    _loc_20 = (_loc_16 - _loc_7) / _loc_19;
                    _loc_10 = _loc_8;
                    while (_loc_10 < _loc_17)
                    {
                        
                        _loc_12 = _loc_7 + (_loc_10 - _loc_8) * _loc_20;
                        var _loc_24:int = 1;
                        _loc_12 = 1;
                        var _loc_24:int = 0;
                        _loc_12 = 0;
                        _loc_11 = _loc_12 * 255;
                        _loc_9.push(_loc_11);
                        _loc_10++;
                    }
                }
                else
                {
                    NumberUtil.getBezierData(_loc_8, _loc_17, _loc_8 + _loc_3.RX, _loc_17 + _loc_14.LX, _loc_4);
                    NumberUtil.getBezierData(_loc_7, _loc_16, _loc_7 + _loc_3.RY, _loc_16 + _loc_14.LY, _loc_5);
                    _loc_10 = _loc_8;
                    while (_loc_10 < _loc_17)
                    {
                        
                        _loc_21 = NumberUtil.getBezierTimeAndValue(_loc_10, _loc_4, null);
                        _loc_22 = _loc_21 * _loc_21;
                        _loc_23 = _loc_22 * _loc_21;
                        _loc_12 = _loc_5.x * _loc_23 + _loc_5.y * _loc_22 + _loc_5.z * _loc_21 + _loc_5.w;
                        var _loc_24:int = 1;
                        _loc_12 = 1;
                        var _loc_24:int = 0;
                        _loc_12 = 0;
                        _loc_11 = _loc_12 * 255;
                        _loc_9.push(_loc_11);
                        _loc_10++;
                    }
                }
                _loc_3 = _loc_14;
                _loc_8 = _loc_17;
                _loc_7 = _loc_16;
                _loc_6 = _loc_15;
                _loc_13++;
            }
            return _loc_9;
        }// end function

        private function getBezierData(param1:Number, param2:Number, param3:Number, param4:Number, param5:Vector3D) : Vector3D
        {
            param5.w = param1;
            param5.z = -3 * param1 + 3 * param3;
            param5.y = 3 * param1 - 6 * param3 + 3 * param4;
            param5.x = -param1 + 3 * param3 - 3 * param4 + param2;
            return param5;
        }// end function

        public function setColor(param1:Array, param2:Array, param3:Array, param4:Boolean) : void
        {
            if (param1 && param2 && param3)
            {
                this._useColor = true;
                if (!this._colorBitmapData)
                {
                    this._colorBitmapData = new BitmapData(bitmapWidth, bitmapHeight, false, 16777215);
                }
                _shape.graphics.clear();
                _shape.graphics.beginGradientFill(GradientType.LINEAR, param1, param2, param3, _matrix, "pad", InterpolationMethod.RGB);
                _shape.graphics.drawRect(0, 0, bitmapWidth, 1);
                if (!param4)
                {
                    _shape.graphics.drawRect(0, 1, bitmapWidth, 1);
                }
                this._colorBitmapData.draw(_shape);
            }
            else
            {
                this._useColor = false;
            }
            return;
        }// end function

        public function setAlpha(param1:Array, param2:Array, param3:Array, param4:Boolean) : void
        {
            if (param1 && param2 && param3)
            {
                this._useAlpha = true;
                if (!this._colorBitmapData)
                {
                    this._colorBitmapData = new BitmapData(bitmapWidth, bitmapHeight, false, 16777215);
                }
                _shape.graphics.clear();
                _shape.graphics.beginGradientFill(GradientType.LINEAR, param1, param2, param3, _matrix, "pad", InterpolationMethod.RGB);
                _shape.graphics.drawRect(0, 2, bitmapWidth, 1);
                if (!param4)
                {
                    _shape.graphics.drawRect(0, 3, bitmapWidth, 1);
                }
                this._colorBitmapData.draw(_shape);
            }
            else
            {
                this._useAlpha = false;
            }
            return;
        }// end function

        public function dispose() : void
        {
            this.clear();
            this.surfaceData = new Object();
            if (this._emitterObject)
            {
                this._emitterObject.dispose();
                this._emitterObject = null;
            }
            if (this._colorBitmapData)
            {
                this._colorBitmapData.dispose();
                this._colorBitmapData = null;
            }
            if (this.colorBitmapdataBytes)
            {
                this.colorBitmapdataBytes.clear();
                this.colorBitmapdataBytes = null;
            }
            return;
        }// end function

        private static function initStatic() : Boolean
        {
            maxConstRegistNum = 90;
            bitmapHeight = 8;
            bitmapWidth = 128;
            _matrix = new Matrix();
            _matrix.createGradientBox(bitmapWidth, 1);
            _shape = new Shape();
            return true;
        }// end function

    }
}
